/**************************************************************************************
*  Component of benchmarking program.
**************************************************************************************
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL RTJ COMPUTING BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************************/
public class MethodBenchmarkUnit extends BenchmarkUnit {

    private int depthCount;
    public int wIterationCount;

    public MethodBenchmarkUnit() {
        name = "Method";
        wIterationCount = 20;
    }

    public int execute() {

        int j = 0;
        for (int i1 = 0; i1 < wIterationCount; i1++) {
            int k = arithmeticSeries(i1);
            int i2 = notInlineableSeries(i1);

            if (k > i2)
                j += i2;
            else
                j += k;
        }
        return j;

    }

    private int arithmeticSeries(int i) {
        if (i == 0)
            return 0;
        else
            return i + arithmeticSeries(i - 1);
    }

    private int notInlineableSeries(int i) {

        int j = i;
        depthCount++;
        if (i == 0)
            return j;
        if ((j & 1) != 0)
            j += notInlineableSeries(i - 1);
        else
            j += 1 + notInlineableSeries(i - 1);

        return j;
    }

}

